﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using ERP_RORZE_SYSTEM;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;

namespace ERP_RORZE_DLL.Assembly
{
    public partial class frm_Add_F4CheckFORS300 : Form
    {
        private INISettings mySetting;
        private SqlConnection myConnection;

        private DataSet ds;
        private DataViewManager dsView;

        private Dictionary<string, string> required_list;

        public frm_Add_F4CheckFORS300()
        {
            InitializeComponent();
            this.mySetting = new INISettings();
            this.myConnection = new SqlConnection(mySetting.SQLConnectionString);
            this.ds = new DataSet("RobotOrderDetail");

            this.required_list = new Dictionary<string, string>() { { "serialNo", "Serial No" }, { "writtenBy", "Written By" },
            { "checkBy", "Check By"}, {"inputDate", "Date"}, {"wiringDiagram", "Wiring Diagram"}, {"magrinY", "Current Magrin Y"}, 
            {"magrinZ", "Current Magrin Z"}, {"pcPower", "PC Power"}, {"pcPowerSerial", "PC Power Serial"}, {"rd023Y", "RD023-Y"},
            {"yRun", "Y Run"}, {"yStop", "Y Stop"}, {"rd023Z", "RD023-Z"}, {"zRun", "Z Run"}, {"zStop", "Z Stop"}, {"rc4201", "RC420-1"}, 
            {"rc4201Ver", "RC420-1-Ver"}, {"rc4202", "RC420-2"}, {"rc4202Ver", "RC420-2-Ver"}, {"rc4203", "RC420-3"}, 
            {"rc4203Ver", "RC420-3-Ver"}, {"rc4204", "RC420-4"}, {"rc4204Ver", "RC420-4-Ver"}, {"rc4205", "RC420-5"}, 
            {"rc4205Ver", "RC420-5-Ver"}, {"rc4206", "RC420-6"}, {"rc4206Ver", "RC420-6-Ver"}, {"y1", "Y1"}, {"y2", "Y2"}, {"y3", "Y3"},
            {"y4", "Y4"}, {"y5", "Y5"}, {"y6", "Y6"}, {"z1", "Z1"}, {"z2", "Z2"}, {"z3", "Z3"}, {"z4", "Z4"}, {"z5", "Z5"}, {"z6", "Z6"},
            {"mappingTop", "Mapping Top"}, {"mappingBottom", "Mapping Bottom"}, {"ipAddress", "IP Address"},
            {"cfImage", "CF Image"}, {"hostName", "Host Name"}, {"hostIPAddr", "Host IP Address"}, {"bodyNo", "Body No"},
            {"pcBoard", "PC Board"}, {"bcr", "BRC"}, {"remark", "Remark"}, {"appDiagram", "Appearance Diagram"},
            {"stackerThres", "Stacker Hand Threshold"}, {"mapperThres", "Mapper Threshold"}, {"laserThres", "Laser Prt Threshold"}};

            LoadSerialList();
            LoadStaffList();
            LoadDefaultData();            
        }

        ////////////////////////////////////////////////////
        /// Load Serial List
        ////////////////////////////////////////////////////
        private void LoadSerialList()
        {
            try
            {
                myConnection.Open();
                SqlCommand cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT [SerialNo], [CompID] FROM [231_RobotOrderDetail]"
                    + " WHERE (FinishedDate > DateAdd(dd, 0, DateDiff(dd, 0, GETDATE())) - 500) AND [SerialNo] NOT IN"
                    + " (SELECT [SerialNo] COLLATE Vietnamese_CI_AS FROM [231_F4RV201])";
                SqlDataAdapter da1 = new SqlDataAdapter();
                da1.SelectCommand = cmd_sql;
                da1.TableMappings.Add("Table", "RobotOrderDetail");
                da1.Fill(ds);
                dsView = ds.DefaultViewManager;
                cmd_sql.Dispose();
                myConnection.Close();

                this.serialNo.DataSource = dsView;
                this.serialNo.DisplayMember = "RobotOrderDetail.SerialNo";
                this.serialNo.ValueMember = "RobotOrderDetail.SerialNo";
                this.serialNo.AutoCompleteSource = AutoCompleteSource.ListItems;

                this.partNo.DataBindings.Add("Text", dsView, "RobotOrderDetail.CompID");
            }
            catch (Exception ex)
            {
                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Close();
                }
                MessageBox.Show(ex.Message);
            }
        }

        /// <summary>
        /// Load Staff List
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoadStaffList()
        {
            try
            {
                myConnection.Open();
                SqlCommand sql_cmd = myConnection.CreateCommand();
                sql_cmd.CommandText = "SELECT StaffID, StaffName FROM [222_Staff] WHERE StopDate IS NULL ORDER BY StaffID";
                SqlDataReader dataReader = sql_cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    string[] fullname = dataReader["StaffName"].ToString().Trim().Split(' ');

                    CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
                    TextInfo textInfo = cultureInfo.TextInfo;
                    string txt = textInfo.ToTitleCase(fullname[fullname.Length - 1].ToLower());

                    item.Text = txt + dataReader["StaffID"].ToString().Trim();
                    //item.Text = dataReader["StaffID"].ToString().Trim() + " - " + dataReader["StaffName"].ToString().Trim();
                    item.Value = dataReader["StaffID"].ToString().Trim();

                    this.writtenBy.Properties.Items.Add(item);
                    this.checkBy.Properties.Items.Add(item);
                }
                dataReader.Close();
                sql_cmd.Dispose();
                myConnection.Close();
            }
            catch (Exception ex)
            {
                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Close();
                }
                MessageBox.Show(ex.Message);
            }
        }

        ////////////////////////////////////////////////////
        /// Load Default Data
        ////////////////////////////////////////////////////
        private void LoadDefaultData()
        {
            try
            {
                myConnection.Open();
                SqlCommand cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [WiringDaiagram] FROM [231_F4RV201]";
                SqlDataReader dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["WiringDaiagram"].ToString().Trim();
                    item.Value = dataReader["WiringDaiagram"].ToString().Trim();
                    this.wiringDiagram.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [PCPower] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["PCPower"].ToString().Trim();
                    item.Value = dataReader["PCPower"].ToString().Trim();
                    this.pcPower.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [RC420_1_Ver] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["RC420_1_Ver"].ToString().Trim();
                    item.Value = dataReader["RC420_1_Ver"].ToString().Trim();
                    this.rc4201Ver.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [RC420_2_Ver] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["RC420_2_Ver"].ToString().Trim();
                    item.Value = dataReader["RC420_2_Ver"].ToString().Trim();
                    this.rc4202Ver.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [RC410_3_Ver] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["RC410_3_Ver"].ToString().Trim();
                    item.Value = dataReader["RC410_3_Ver"].ToString().Trim();
                    this.rc4103Ver.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [RC410_4_Ver] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["RC410_4_Ver"].ToString().Trim();
                    item.Value = dataReader["RC410_4_Ver"].ToString().Trim();
                    this.rc4104Ver.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [RC410_5_Ver] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["RC410_5_Ver"].ToString().Trim();
                    item.Value = dataReader["RC410_5_Ver"].ToString().Trim();
                    this.rc4105Ver.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [RC410_6_Ver] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["RC410_6_Ver"].ToString().Trim();
                    item.Value = dataReader["RC410_6_Ver"].ToString().Trim();
                    this.rc4106Ver.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [Ver] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["Ver"].ToString().Trim();
                    item.Value = dataReader["Ver"].ToString().Trim();
                    this.softVer.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [IP_Adress] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["IP_Adress"].ToString().Trim();
                    item.Value = dataReader["IP_Adress"].ToString().Trim();
                    this.ipAddress.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [CF Image] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["CF Image"].ToString().Trim();
                    item.Value = dataReader["CF Image"].ToString().Trim();
                    this.cfImage.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();

                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT DISTINCT [Appearance Diagram] FROM [231_F4RV201]";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text = dataReader["Appearance Diagram"].ToString().Trim();
                    item.Value = dataReader["Appearance Diagram"].ToString().Trim();
                    this.appDiagram.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();
                
                cmd_sql = myConnection.CreateCommand();
                cmd_sql.CommandText = "SELECT [SerialNo] FROM [231_F5Detail]"
                    + " WHERE ([FinishDate] > DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) - 500)";
                dataReader = cmd_sql.ExecuteReader();
                while (dataReader.Read())
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Value = dataReader["SerialNo"].ToString().Trim();
                    item.Text = dataReader["SerialNo"].ToString().Trim();

                    this.pcPowerSerial.Properties.Items.Add(item);
                    this.rd023Y.Properties.Items.Add(item);
                    this.rd023Z.Properties.Items.Add(item);
                    this.rc4201.Properties.Items.Add(item);
                    this.rc4202.Properties.Items.Add(item);
                    this.rc4103.Properties.Items.Add(item);
                    this.rc4104.Properties.Items.Add(item);
                    this.rc4105.Properties.Items.Add(item);
                    this.rc4106.Properties.Items.Add(item);
                }
                dataReader.Close();
                cmd_sql.Dispose();
                myConnection.Close();
            }
            catch (Exception ex)
            {
                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Close();
                }
                MessageBox.Show(ex.Message);
            }
        }
        
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        
        ///////////////////////////
        /// When Click Add Button
        ///////////////////////////        
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string error = null;            
            if (this.serialNo.SelectedIndex < 0)
            {
                error = "Please select Serial No"; 
            }

            if (string.IsNullOrEmpty(error))
            {
                foreach (Control c in this.Controls)
                {
                    if (c is System.Windows.Forms.ComboBox)
                    {                        
                        if ((((System.Windows.Forms.ComboBox)c).SelectedIndex < 0) && string.IsNullOrEmpty(((System.Windows.Forms.ComboBox)c).Text))
                        {
                            if (required_list.ContainsKey(((System.Windows.Forms.ComboBox)c).Name))
                            {
                                error = "Please select " + required_list[((System.Windows.Forms.ComboBox)c).Name];
                            }
                        }
                    }

                    if (c is DevExpress.XtraEditors.ComboBoxEdit)
                    {
                        if ((((DevExpress.XtraEditors.ComboBoxEdit)c).SelectedIndex < 0) && string.IsNullOrEmpty(((DevExpress.XtraEditors.ComboBoxEdit)c).Text))
                        {
                            if (required_list.ContainsKey(((DevExpress.XtraEditors.ComboBoxEdit)c).Name))
                            {
                                error = "Please select " + required_list[((DevExpress.XtraEditors.ComboBoxEdit)c).Name];
                            }
                        }
                    }

                    if (c is DevExpress.XtraEditors.TextEdit)
                    {
                        if (string.IsNullOrEmpty(((DevExpress.XtraEditors.TextEdit)c).Text.Trim()))
                        {
                            if (required_list.ContainsKey(((DevExpress.XtraEditors.TextEdit)c).Name))
                            {
                                error = "Please enter " + required_list[((DevExpress.XtraEditors.TextEdit)c).Name];
                            }
                        }
                    }

                    if (c is System.Windows.Forms.TextBox)
                    {
                        if (string.IsNullOrEmpty(((System.Windows.Forms.TextBox)c).Text.Trim()))
                        {
                            if (required_list.ContainsKey(((System.Windows.Forms.TextBox)c).Name))
                            {
                                error = "Please enter " + required_list[((System.Windows.Forms.TextBox)c).Name];
                            }
                        }
                    }

                    if (c is System.Windows.Forms.GroupBox)
                    {
                        foreach (Control sub_c in c.Controls)
                        {
                            if (sub_c is DevExpress.XtraEditors.TextEdit)
                            {
                                if (string.IsNullOrEmpty(((DevExpress.XtraEditors.TextEdit)sub_c).Text.Trim()))
                                {
                                    if (required_list.ContainsKey(((DevExpress.XtraEditors.TextEdit)sub_c).Name))
                                    {
                                        error = "Plaase enter " + required_list[((DevExpress.XtraEditors.TextEdit)sub_c).Name];
                                    }
                                }
                            }

                            if (sub_c is DevExpress.XtraEditors.ComboBoxEdit)
                            {
                                if ((((DevExpress.XtraEditors.ComboBoxEdit)sub_c).SelectedIndex < 0) && string.IsNullOrEmpty(((DevExpress.XtraEditors.ComboBoxEdit)sub_c).Text))
                                {
                                    if (required_list.ContainsKey(((DevExpress.XtraEditors.ComboBoxEdit)sub_c).Name))
                                    {
                                        error = "Please select " + required_list[((DevExpress.XtraEditors.ComboBoxEdit)sub_c).Name];
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(error))
            {
                DateTime date = DateTime.Parse(this.inputDate.EditValue.ToString());
                try
                {
                    myConnection.Open();
                    SqlCommand sql_cmd = myConnection.CreateCommand();
                    sql_cmd.CommandText = "INSERT INTO [231_F4RV201] ([SerialNo], [Written], [Date], [Checked],"
                        + " [WiringDaiagram], Y, Z, [PCPower], [PCPowerSerial], [RC420_1], [RC420_1_Ver],"
                        + " [RC420_2], [RC420_2_Ver], [RC410_3], [RC410_3_Ver], [RC410_4], [RC410_4_Ver], [RC410_5],"
                        + " [RC410_5_Ver], [RC410_6], [RC410_6_Ver], [RD023_Y], [Y_Run], [Y_Stop], [RD023_Z], [Z_Run],"
                        + " [Z_Stop], [Y1], [Y2], [Y3], [Y4], [Y5], [Y6], [Z1], [Z2], [Z3], [Z4], [Z5], [Z6], [Top],"
                        + " [Bottom], [Ver], [IP_Adress], [PC_Board], [BCR], [Host name], [Host IP Adrs], [Body No],"
                        + " [Remark], [BCR data], [CF Image], [Appearance Diagram], [Mapper Threshold],"
                        + " [Stacker Hand Threshold], [Laser Prt Threshold], [RC420_1_Ex_Ver], [RC420_2_Ex_Ver],"
                        + " [Y_OH], [Y_OL], [Y_QI], [Y_OA], [Y_OB], [Y_OS], [Y_0S], [Z_OH], [Z_OL], [Z_QI], [Z_OA],"
                        + " [Z_OB], [Z_OS], [Z_0S], [a35], [b35], [c35], [d35], [A], [/A], [B], [/B], [C], [/C], [D],"
                        + " [/D], [E], [/E], [F], [/F], [G], [/G], [H], [/H], [Foup], [Fosb], [OC25], [OC13],"
                        + " [Foup Slot Num], [Foup Slot Pitch], [Foup Min Thickness], [Foup Max Thickness],"
                        + " [Foup Offset], [Foup Bow], [Fosb Slot Num], [Fosb Slot Pitch], [Fosb Min Thickness],"
                        + " [Fosb Max Thickness], [Fosb Offset], [Fosb Bow], [OC25 Slot Num], [OC25 Slot Pitch],"
                        + " [OC25 Min Thickness], [OC25 Max Thickness], [OC25 Offset], [OC25 Bow], [OC13 Slot Num],"
                        + " [OC13 Slot Pitch], [OC13 Min Thickness], [OC13 Max Thickness], [OC13 Offset], [OC13 Bow],"
                        + " [OS when Pod Unload], [Timer(Pod Clamp/Rotate)], [Timer(Lock Key)], [Timer(Mapper Move)],"
                        + " [Timer(Vacuum)], [OS when SUndock], [Wait for mapping], [OA when SUndock], [Timer(BCR)],"
                        + " [Timer(PRS)], [Timer(Placement)], [Timer(Presence)], [Timer(Rotation)], [Pulse Vacuum Retry],"
                        + " [Default Map], [Host Port])"
                        + " VALUES ('" + this.serialNo.SelectedValue.ToString() + "', '" + this.writtenBy.Text.Trim() + "',"
                        + " @date, '" + this.checkBy.Text.Trim() + "', '" + this.wiringDiagram.Text.Trim() + "',"
                        + " '" + this.magrinY.Text.Trim() + "', '" + this.magrinZ.Text.Trim() + "',"
                        + " '" + this.pcPower.Text.Trim() + "', '" + this.pcPowerSerial.Text.Trim() + "',"
                        + " '" + this.rc4201.Text.Trim() + "', '" + this.rc4201Ver.Text.Trim() + "',"
                        + " '" + this.rc4202.Text.Trim() + "', '" + this.rc4202Ver.Text.Trim() + "',"
                        + " '" + this.rc4103.Text.Trim() + "', '" + this.rc4103Ver.Text.Trim() + "',"
                        + " '" + this.rc4104.Text.Trim() + "', '" + this.rc4104Ver.Text.Trim() + "',"
                        + " '" + this.rc4105.Text.Trim() + "', '" + this.rc4105Ver.Text.Trim() + "',"
                        + " '" + this.rc4106.Text.Trim() + "', '" + this.rc4106Ver.Text.Trim() + "',"
                        + " '" + this.rd023Y.Text.Trim() + "', '" + this.yRun.Text.Trim() + "',"
                        + " '" + this.yStop.Text.Trim() + "', '" + this.rd023Z.Text.Trim() + "',"
                        + " '" + this.zRun.Text.Trim() + "', '" + this.zStop.Text.Trim() + "',"
                        + " '" + this.y1.Text.Trim() + "', '" + this.y2.Text.Trim() + "',"
                        + " '" + this.y3.Text.Trim() + "', '" + this.y4.Text.Trim() + "',"
                        + " '" + this.y5.Text.Trim() + "', '" + this.y6.Text.Trim() + "',"
                        + " '" + this.z1.Text.Trim() + "', '" + this.z2.Text.Trim() + "',"
                        + " '" + this.z3.Text.Trim() + "', '" + this.z4.Text.Trim() + "',"
                        + " '" + this.z5.Text.Trim() + "', '" + this.z6.Text.Trim() + "',"
                        + " '" + this.mappingTop.Text.Trim() + "', '" + this.mappingBottom.Text.Trim() + "',"
                        + " '" + this.softVer.Text.Trim() + "',"
                        + " '" + this.ipAddress.Text.Trim() + "', '" + this.pcBoard.Text.Trim() + "',"
                        + " '" + this.bcr.Text.Trim() + "', '" + this.hostName.Text.Trim() + "',"
                        + " '" + this.hostIPAddr.Text.Trim() + "', '" + this.bodyNo.Text.Trim() + "',"
                        + " '" + this.remark.Text.Trim() + "', '" + this.bcrData.Text.Trim() + "',"
                        + " '" + this.cfImage.Text.Trim() + "', '" + this.appDiagram.Text.Trim() + "',"
                        + " '" + this.mapperThres.Text.Trim() + "', '" + this.stackerThres.Text.Trim() + "',"
                        + " '" + this.laserThres.Text.Trim() + "', '***', '***', '***', '***', '***', '***', '***',"
                        + " '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***',"
                        + " '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***',"
                        + " '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***',"
                        + " '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***',"
                        + " '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***', '***',"
                        + " '***', '***', '***', '***', '***', '***', '***', '***')";
                    sql_cmd.Parameters.Add("@date", SqlDbType.DateTime).Value = date.Date;
                    sql_cmd.ExecuteNonQuery();
                    sql_cmd.Dispose();
                    myConnection.Close();
                    MessageBox.Show("Database updated successfully!");
                    this.Dispose();
                }
                catch (Exception ex)
                {
                    if (myConnection.State == ConnectionState.Open)
                    {
                        myConnection.Close();
                    }
                    MessageBox.Show(ex.Message);
                }                
            }
            else
            {
                MessageBox.Show(error);
            }
        }

        private void serialNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.serialNo.SelectedIndex >= 0)
            {                
                if (this.serialNo.Text.Substring(this.serialNo.Text.Length - 1, 1).ToUpper() == "F")
                {
                    this.TSerialNo.Text = this.serialNo.Text.Substring(0, this.serialNo.Text.Length - 1);
                }
                else
                {
                    this.TSerialNo.Text = this.serialNo.Text;
                }
            }
        }

    }
}
